from django.db import models

# Create your models here.

"""
通过django建表执行命令：
python manage.py makemigrations
python manage.py migrate
"""

class Department(models.Model):
    """ 部门表 """
    deptname = models.CharField(verbose_name="部门名称", max_length=32)

    # 添加重写toString方法 页面显示是部门名称
    def __str__(self):
        return self.deptname

class UserInfo(models.Model):
    """ 员工表 """
    name = models.CharField(verbose_name="员工名称", max_length=64)
    password = models.CharField(verbose_name="密码", max_length=32)
    age = models.IntegerField(verbose_name="年龄")
    amount = models.DecimalField(verbose_name="账号余额", max_digits=10, decimal_places=2,default=0)
    #create_time = models.DateTimeField(verbose_name="入职时间")
    create_time = models.DateField(verbose_name="入职时间")
    #无约束
    # depart_id = models.BigIntegerField(verbose_name="部门ID")

    # 1.有约束
    #  - to, 与哪个表关联
    #  - to_field, 表中哪一列关联
    # 2. django自动
    #  - 写的depart
    #  - 生成数据列 depart_id
    # 3. 如果部门表删除
    # 3.1  - 级联删除
    depart = models.ForeignKey(verbose_name="部门名称",to="Department", to_field="id", on_delete=models.CASCADE)
    # 3.2  - 部门ID置为空
    #depart_id = models.ForeignKey(to="Department", to_field="id",null=True, blank=True, on_delete=models.SET_NULL)

    # 在django中做的约束 元组
    gender_choices = (
        (0, '男'),
        (1, '女'),
    )
    gender = models.SmallIntegerField(verbose_name="性别", choices=gender_choices)

class PrettyNum(models.Model):
    """ 靓号表 """
    mobile = models.CharField(verbose_name="手机号", max_length=11)
    #允许为空 增加 blank=True, null=True
    price = models.IntegerField(verbose_name="单价/分", default=0, blank=True, null=True)
    level_choices = (
        (1, "1级"),
        (2, "2级"),
        (3, "3级"),
        (4, "4级"),
    )
    level = models.SmallIntegerField(verbose_name="级别", default=1, choices=level_choices)
    status_choices = (
        (1, "已占用"),
        (2, "未使用"),
    )
    status = models.SmallIntegerField(verbose_name="状态", default=2, choices=status_choices)





